﻿
@{
    ViewBag.Title = "返工详情";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var reviewStatues = (ViewBag.ReviewStatusEnum as List<KeyValuePair<int, string>>).Where(_ => _.Key > 1).ToList();
}
@model IOA.MES.DataAccess.VModel.VReworkOrder

@section Contents{
    <style>
        .layui-input-inline {
            padding: 6px 0 !important;
        }

        .reworkItem {
            padding: 5px 10px;
            border: 1px solid #ff6a00;
            margin: 0 10px 10px 0;
            float: left;
        }

        .reworkItem {
            float: left;
            background-color: #FAFAFA;
            border: 1px solid #F6F6F6;
            padding: 5px 10px;
            margin: 0 10px 10px 0;
        }

            .reworkItem .layui-icon-delete {
                color: red;
                margin-left: 5px;
            }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div style="padding: 20px; background-color: #F2F2F2;">
        <div class="layui-card">
            <div class="layui-card-body">
                <div class="layui-row">
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ReworkNo">返工单号：</label>
                        <div class="layui-input-inline">
                            {{model.ReworkNo}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ReworkType">返工类型：</label>
                        <div class="layui-input-inline">
                            {{model.CNReworkType}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ReworkWorkshop">返工车间：</label>
                        <div class="layui-input-inline">
                            {{model.WorkshopName}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ReworkProcess">返工工序：</label>
                        <div class="layui-input-inline">
                            <span v-for="site in model.Sites" style="padding:5px;background-color:#ff6a00;color:#FFF;margin:1px;">{{site.SiteName}}</span>
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.OrderNo">订单号：</label>
                        <div class="layui-input-inline">
                            {{model.OrderNo}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CustomerCode">客户代码：</label>
                        <div class="layui-input-inline">
                            {{model.CustomerCode}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CustomerName">客户名称：</label>
                        <div class="layui-input-inline">
                            {{model.CustomerName}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.CreateTime">创建时间：</label>
                        <div class="layui-input-inline">
                            {{model.CreateTimeStr}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ApprovalStatus">审核状态：</label>
                        <div class="layui-input-inline">
                            {{model.OrderNo}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ApprovalBy">审核人：</label>
                        <div class="layui-input-inline">
                            {{model.CNReviewBy}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ApprovalTime">审核时间：</label>
                        <div class="layui-input-inline">
                            {{model.ReviewTimeStr}}
                        </div>
                    </div>
                    <div class="layui-col-xs3 layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ApprovalDesc">审核说明：</label>
                        <div class="layui-input-inline">
                            {{model.ReviewDesc}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">
                {{lang.Field.ReworkList}}（{{model.CNReworkType}}）
            </div>
            <div class="layui-card-body" style="display: flow-root;">
                <div class="reworkItem" v-for="item in model.Items">{{item.ReworkItemNo}}</div>
                <div v-if="model.Items.length<=0" style="padding:20px; text-align:center;">暂无返工清单</div>
            </div>
        </div>
        <div class="layui-card">
            <div class="layui-card-header">
                {{lang.Field.ReworkUseMaterials}}
            </div>
            <div class="layui-card-body">
                <div v-if="model.Items.length<=0" style="padding:20px; text-align:center;">暂无返工扣料</div>
                <table lay-filter="table" id="table"></table>
            </div>
        </div>
        <div class="layui-card layui-form" v-if="model.ReviewStatus==1">
            <div class="layui-card-header">
                {{lang.Field.ReworkReview}}
            </div>
            <div class="layui-card-body">
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" v-html="lang.Field.ApprovalResult">审核结果：</label>
                    <div class="layui-input-block">
                        <select id="selReviewStatus" lay-filter="selReviewStatus">
                            @foreach (var item in reviewStatues)
                            {
                                <option value="@item.Key">@item.Value</option>
                            }
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label" v-html="lang.Field.ApprovalDesc">审核说明：</label>
                    <div class="layui-input-block">
                        <textarea id="txtReviewDesc" placeholder="请输入审核说明" class="layui-textarea"></textarea>
                    </div>
                </div>
                <div class="layui-form-item layui-form-text">
                    <div class="layui-input-block">
                        <button type="button" class="layui-btn" @@click="review" v-html="lang.Field.SubmitApprival">确定审核</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var model = @Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model));
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package,
                reworkNo: "@Model.ReworkNo",
                model: model
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['form', 'layer', 'index', 'table', 'laydate'], function () {
                var layer = layui.layer,
                    form = layui.form,
                    table = layui.table;
                if (vm.$data.model.Boms.length > 0) {
                    var options = {
                        elem: '#table'
                        , data: vm.$data.model.Boms
                        , page: false
                        , limit: vm.$data.model.Boms.length
                        , cols: [[
                            { title: '序号', type: "numbers", width: 60 }
                            , { field: 'CategoryCode', title: '分类代码', minWidth: 150 }
                            , { field: 'CategoryName', title: '分类名称', minWidth: 100 }
                            , { field: 'Quality', title: '扣料数量', minWidth: 150 }
                        ]]
                    };
                    table.render(options);
                }
            });
        }

        function review() {
            var status = parseInt($("#selReviewStatus").val());
            var desc = $("#txtReviewDesc").val().trim();

            var loadId = layer.load();
            $.ajax({
                url: "/Plan/ReviewRework",
                data: {
                    model: {
                        ReworkNo: vm.$data.reworkNo,
                        ReviewDesc: desc,
                        ReviewStatus: status
                    }
                },
                complete: function () {
                    layer.close(loadId);
                },
                success: function (res) {
                    if (res.ErrCode != 200) {
                        layer.msg(res.ErrMsg, { icon: 5 });
                        return;
                    }
                    layer.msg("审核成功！", { icon: 6 });
                    location.reload();
                }
            });
        }
    </script>
}
